//
//  ChooseCountryCell.m
//  HuaRun2
//
//  Created by admin on 2017/11/5.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "ChooseCountryCell.h"
#import "CompanyModel.h"
#import "ConditionModel.h"

@interface ChooseCountryCell ()

@property (nonatomic, strong) UILabel * guoJiKeyLab;
@property (nonatomic, strong) UILabel * guoJiValueLab;

@end

@implementation ChooseCountryCell


- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        

        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    
    [super viewInit];

    self.contentView.backgroundColor = [UIColor whiteColor];
    self.backView.backgroundColor = RGBA(249, 249, 249, 1);

    [self.contentView addSubview:self.guoJiKeyLab];
    [self.contentView addSubview:self.guoJiValueLab];
    [self.contentView addSubview:self.iconBtn];
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(0);
        make.bottom.mas_equalTo(ws.contentView).offset(-kMargin10);
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(ws.backView);
        make.left.mas_equalTo(ws.backView).mas_equalTo(kMargin10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    [self.guoJiKeyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.backView).mas_equalTo(kMargin10/2);
        make.left.mas_equalTo(ws.iconBtn.mas_right).mas_equalTo(kMargin10);
        make.right.mas_equalTo(ws.contentView).mas_equalTo(-kMargin10);
//        make.height.mas_equalTo(20);
    }];
    
    [self.guoJiValueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.guoJiKeyLab.mas_bottom).mas_equalTo(kMargin10/ 2);
        make.left.right.mas_equalTo(ws.guoJiKeyLab);
//        make.height.mas_equalTo(ws.guoJiKeyLab);
//        make.bottom.mas_equalTo(ws.contentView).offset(-kMargin10);
    }];
}

#pragma mark getter setter
- (void)setCompanyModel:(CompanyModel *)companyModel {
    _companyModel = companyModel;
    _guoJiKeyLab.text = [NSString stringWithFormat:@"%@", companyModel.name];
    _guoJiValueLab.text = [NSString stringWithFormat:@"%@", companyModel.companyNameChineseC];

    if (companyModel.isSelected) {
        self.backView.backgroundColor = [UIColor orangeColor];
    }else {
        self.backView.backgroundColor = RGBA(249, 249, 249, 1);
    }
    
    _iconBtn.selected = companyModel.isSelected;
}

- (void)setConditionModel:(ConditionModel *)conditionModel {
    _conditionModel = conditionModel;
    _guoJiKeyLab.text = [NSString stringWithFormat:@"%@", conditionModel.value];
    _guoJiValueLab.text = [NSString stringWithFormat:@"%@", conditionModel.valueCinese];
    if (conditionModel.isSelected) {
        self.backView.backgroundColor = [UIColor orangeColor];
    }else {
        self.backView.backgroundColor = RGBA(249, 249, 249, 1);
    }
    
    _iconBtn.selected = conditionModel.isSelected;
}

//"nationality"= "国籍";//
- (UILabel *)guoJiKeyLab {
    if (!_guoJiKeyLab) {
        self.guoJiKeyLab = [UILabel new];
        _guoJiKeyLab.textAlignment = NSTextAlignmentLeft;
        _guoJiKeyLab.font = [UIFont boldSystemFontOfSize:12];
        _guoJiKeyLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _guoJiKeyLab.text = NSLocalizedString(@"nationality", nil);
        //        @"国籍";
//        _guoJiKeyLab.backgroundColor = kRandomColor;
//        _guoJiKeyLab.numberOfLines = 0;
    }
    return _guoJiKeyLab;
}


- (UILabel *)guoJiValueLab {
    if (!_guoJiValueLab) {
        self.guoJiValueLab = [UILabel new];
        _guoJiValueLab.textAlignment = NSTextAlignmentLeft;
        _guoJiValueLab.font = kGeneralFontSize;
        _guoJiValueLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _guoJiValueLab.text = @"value";
//        _guoJiValueLab.backgroundColor = kRandomColor;
//        _guoJiValueLab.numberOfLines = 0;
    }
    return _guoJiValueLab;
}

- (UIButton *)iconBtn {
    if (!_iconBtn) {
        self.iconBtn = [UIButton new];
        [_iconBtn setBackgroundImage:[UIImage imageNamed:@"未选中-1"]
                            forState:(UIControlStateNormal)];
        [_iconBtn setBackgroundImage:[UIImage imageNamed:@"选中按钮"]
                            forState:(UIControlStateSelected)];
        _iconBtn.userInteractionEnabled = NO;
    }
    return _iconBtn;
}
@end
